package com.example.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.slf4j.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class ServiceLoggingAspect {
    private static final Logger log = LoggerFactory.getLogger(ServiceLoggingAspect.class);

    /** 切点：拦截 com.example.service 包及子包所有方法 */
    @Pointcut("within(com.example.service..*)")
    public void anyServiceMethod() {}

    /** 方法调用之前打印一条日志 */
    @Before("anyServiceMethod()")
    public void logBefore(JoinPoint jp) {
        String cls = jp.getTarget().getClass().getSimpleName();
        String mth = jp.getSignature().getName();
        log.info("[AOP] calling {}.{}()", cls, mth);
    }
}
